package com.ruoyi.project.management.task1.service;

import com.ruoyi.common.constant.UserConstants;
import com.ruoyi.common.utils.security.ShiroUtils;
import com.ruoyi.common.utils.text.Convert;
import com.ruoyi.project.management.task1.domain.Task1;
import com.ruoyi.project.management.task1.mapper.ManagementTaskMapper1;
import com.ruoyi.project.system.dept.mapper.DeptMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
@Service
public class ManagementTaskService11Impl implements ManagementTaskService1 {
    @Autowired
    private ManagementTaskMapper1 managementTaskMapper1;
    @Autowired
    private DeptMapper deptMapper;
    @Override
    public List<Task1> selectMore(Task1 task1) {
        List<Task1> list = managementTaskMapper1.selectMore(task1);
        return list;
    }

    @Override
    public String checkTaskTitleUnique(Task1 task) {
        Task1 task1 = managementTaskMapper1.selectOne(task);
        if (task1 != null) {
            return UserConstants.TASK_NAME_NOT_UNIQUE;
        }
        return UserConstants.TASK_NAME_UNIQUE;
    }

    @Override
    public int insertTask(Task1 task1) {

        task1.setIssue(ShiroUtils.getLoginName());
        ShiroUtils.clearCachedAuthorizationInfo();
        return managementTaskMapper1.insert(task1);
    }

    @Override
    public Task1 selectTaskById(Long task_id) {
        Task1 task1 = managementTaskMapper1.selectById(task_id);
        String userName = task1.getUserName();
        String deptName = deptMapper.selectDeptName(userName);
        task1.setDeptName(deptName);
        String companyName = deptMapper.selectCompanyName(userName);
        task1.setCompanyName(companyName);
        return task1;
    }

    @Override
    public int deleteTaskByIds(String ids) {
        Long[] postIds = Convert.toLongArray(ids);
        return managementTaskMapper1.deleteTaskByIds(postIds);
    }

    @Override
    public int updateTask(Task1 task1) {
        task1.setIssue(ShiroUtils.getLoginName());
        ShiroUtils.clearCachedAuthorizationInfo();
        return managementTaskMapper1.update(task1);
    }
}
